//
//  ViewController.m
//  selfLocation
//
//  Created by h92 on 15/1/7.
//  Copyright (c) 2015年 李腾飞. All rights reserved.
//

#import "ViewController.h"


@interface ViewController ()<CLLocationManagerDelegate>

@end

@implementation ViewController
@synthesize locationManager;
@synthesize latitudeTextField;
@synthesize highTextField;
@synthesize longtitudeTextField;

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initView];
}
-(void)viewDidAppear:(BOOL)animated
{
     [locationManager startUpdatingLocation];
}

-(void)viewDidDisappear:(BOOL)animated
{
    [locationManager stopUpdatingLocation];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


/*---------------------------初始化的方法----------------------------------*/
-(void)initView
{
    locationManager=[[CLLocationManager alloc]init];
    //   locationManager=[CLLocationManager new];
    [locationManager requestAlwaysAuthorization ];
    locationManager.delegate=self;
    locationManager.desiredAccuracy=kCLLocationAccuracyBest;
    //authorization 授权，认可
    
    locationManager.distanceFilter=1000.0f;
    if ([CLLocationManager locationServicesEnabled]==NO)
    {
        NSLog(@"设备不可用");
    }
}

/*---------------------------locationmanagerdelegate的方法----------------------------------*/

// 小译：-（）位置管理员：某位置管理员 已经更新的位置信息：某位置信息
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
{
    CLLocation *currentLocation=[locations lastObject];
    longtitudeTextField.text=[NSString stringWithFormat:@"%3.5f",currentLocation.coordinate.longitude];
    latitudeTextField.text=[NSString stringWithFormat:@"%3.5f",currentLocation.coordinate.latitude];
    highTextField.text=[NSString stringWithFormat:@"%3.5f",currentLocation.altitude];
}


// 小译：-（）位置管理员：某位置管理员 已经更改了的授权状态：某授权状态
-(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
{
    NSLog(@"haha");
}

// 调用失败
// 小译：-（）位置管理员：某管理员 已经失败的错误信息：某错误信息
-(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error
{
    // 小译：deny拒绝
    if(error.code==kCLErrorDenied)
    {
        NSLog(@"拒绝访问");
    }else if (error.code==kCLErrorLocationUnknown)
    {
        NSLog(@"位置信息未知");
    }
}


//
@end
